<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计数某些特殊词出现的频率</title>
</head>
<body>
    <script>
        let string = 'kapilalipak';

        const table={};
        for(let char of string) {
            table[char]=table[char]+1 || 1;
        }
        console.log('%c   table: ','color: MidnightBlue; background: Aquamarine; font-size: 20px;', table);


        const countMap = new Map();
        for (let i = 0; i < string.length; i++) {
            if (countMap.has(string[i])) {
                countMap.set(string[i], countMap.get(string[i]) + 1);
            } else {
                countMap.set(string[i], 1);
            }
        }
        console.log('%c   countMap: ','color: MidnightBlue; background: Aquamarine; font-size: 20px;', countMap);

        // 输出
        // Map(5) {"k" => 2, "a" => 3, "p" => 2, "i" => 2, "l" => 2}

        // 输出
        // {k: 2, a: 3, p: 2, i: 2, l: 2}

    </script>
</body>
</html>